﻿var t;
var init; // the init will be used if initial time is set from the server.
var date;

window.onload = function () {
    init = 1;
    t = setTimeout("RefreshDate()", 100);
}

function RefreshDate()
{
    if (init) {
        date = new Date(document.getElementById("TimeLabel").innerHTML);
        //date = new Date();
        init = 0;
    }
    else {
        date.setMinutes(date.getMinutes() + 1); //this is used if initial time is set from the server
        //date = new Date();
    }
    
    //date
    var day = AdjustTimePart(date.getDate());
    var month = AdjustTimePart(AdjustMonth(date.getMonth()));
    var year = date.getFullYear();
    
    //time
    var minutes = AdjustTimePart(date.getMinutes());
    var hours = AdjustTimePart(date.getHours());
    
    var time = day + "/" + month + "/" + year + "\n" + hours + ":" + minutes;

    document.getElementById("TimeLabel").innerHTML = time.toString();

    setTimeout("RefreshDate()", 60000);
}

function AdjustTimePart(timePart)
{
    if (timePart < 10) return "0" + timePart;
    return timePart;
}

function AdjustMonth(month) 
{
    return ++month;
}